package com.ytheima;

import java.util.TreeMap;

public class TreeMapDemo {
    public static void main(String[] args) {
        test2();
    }
    public static void test1() {
        TreeMap<Student,String> treeMap = new TreeMap<>();
        treeMap.put(new Student("小张",20),"广州");
        treeMap.put(new Student("小赵",21),"深圳");
        treeMap.put(new Student("小王",18),"北京");
        treeMap.put(new Student("小李",19),"上海");

        treeMap.forEach((k,v)-> System.out.println(k + ":" + v));
    }
    public static void test2() {//TreeMap的使用案列-排序
        TreeMap<Student,String> treeMap = new TreeMap<>((o1, o2) -> o2.getAge() - o1.getAge());
        treeMap.put(new Student("小张",20),"广州");
        treeMap.put(new Student("小赵",21),"深圳");
        treeMap.put(new Student("小王",18),"北京");
        treeMap.put(new Student("小李",19),"上海");

        treeMap.forEach((k,v)-> System.out.println(k + ":" + v));
    }
}
